package com.jl.jlapp.popu;

import android.content.Context;
import android.content.res.Resources;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestBuilder;
import com.bumptech.glide.RequestManager;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseQuickAdapter.OnItemClickListener;
import com.jl.jlapp.R;
import com.jl.jlapp.adapter.GoodsMsgSpecificationAdapter;
import com.jl.jlapp.adapter.ShopCartPageGoodsSpecificationAdapter;
import com.jl.jlapp.eneity.GoodsDetailModel;
import com.jl.jlapp.eneity.GoodsDetailModel.ResultDataBean;
import com.jl.jlapp.eneity.GoodsDetailModel.ResultDataBean.GoodsSpecificationDetailsBean;
import com.jl.jlapp.eneity.GoodsDetailModel.ResultDataBean.GoodsSpecificationDetailsBean.GoodsDisplayPicturesBean;

import java.util.List;

public class GoodsDetailActivityChooseGoodsSpecPopu
        extends PopupWindow {
    String checkedGoodsSpec = "";
    Integer checkedGoodsSpecId = Integer.valueOf(0);
    private ImageView closeBtn;
    Integer goodsId = Integer.valueOf(0);
    private GoodsMsgSpecificationAdapter goodsMsgSpecificationAdapter;
    private ImageView goodsSpecImg;
    private TextView goodsSpecNo;
    private TextView goodsSpecPrice;
    List<GoodsDetailModel.ResultDataBean.GoodsSpecificationDetailsBean> goodsSpecificationDetailsBeans;
    private RecyclerView goodsSpecificationRecyclerView;
    private Integer isPresell = Integer.valueOf(0);
    private TextView okBtn;
    private OnClickOkBtnListener onClickOkBtnListener;
    private ShopCartPageGoodsSpecificationAdapter shopCartPageGoodsSpecificationAdapter;
    private TextView tReduce;
    private TextView textView;
    private TextView tvAdd;
    private EditText tvBuyNum;
    private View view;

    public GoodsDetailActivityChooseGoodsSpecPopu(final Context paramContext, String paramString, final GoodsDetailModel.ResultDataBean paramResultDataBean) {
        super(paramContext);
        this.goodsSpecificationDetailsBeans = paramResultDataBean.getGoodsSpecificationDetails();
        this.checkedGoodsSpec = paramString;
        this.view = ((LayoutInflater) paramContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.choose_goods_spec_popup_layout, null);
        this.textView = ((TextView) this.view.findViewById(R.id.shadow_part));
        this.okBtn = ((TextView) this.view.findViewById(R.id.choose_spec_bottom_btn));
        this.goodsSpecPrice = ((TextView) this.view.findViewById(R.id.goods_spec_price));
        this.goodsSpecNo = ((TextView) this.view.findViewById(R.id.goods_spec_no));
        this.goodsSpecImg = ((ImageView) this.view.findViewById(R.id.goods_spec_img));
        this.tvBuyNum = ((EditText) this.view.findViewById(R.id.tv_buy_num));
        this.tReduce = ((TextView) this.view.findViewById(R.id.tv_reduce));
        this.tvAdd = ((TextView) this.view.findViewById(R.id.tv_add));
        this.closeBtn = ((ImageView) this.view.findViewById(R.id.close_btn));
        ((RelativeLayout) this.view.findViewById(R.id.choose_spec_num_layout)).setVisibility(View.VISIBLE);
        this.goodsSpecificationRecyclerView = ((RecyclerView) this.view.findViewById(R.id.goods_spec_recycler_view));
        int i = 0;
        if (i < this.goodsSpecificationDetailsBeans.size()) {
            if (this.checkedGoodsSpec.equals(((GoodsDetailModel.ResultDataBean.GoodsSpecificationDetailsBean) this.goodsSpecificationDetailsBeans.get(i)).getSpecifications())) {
                this.isPresell = Integer.valueOf(((GoodsDetailModel.ResultDataBean.GoodsSpecificationDetailsBean) this.goodsSpecificationDetailsBeans.get(i)).getGxcGoodsState());
                this.checkedGoodsSpecId = Integer.valueOf(((GoodsDetailModel.ResultDataBean.GoodsSpecificationDetailsBean) this.goodsSpecificationDetailsBeans.get(i)).getId());
                this.goodsId = Integer.valueOf(((GoodsDetailModel.ResultDataBean.GoodsSpecificationDetailsBean) this.goodsSpecificationDetailsBeans.get(i)).getGoodsId());
                this.goodsSpecPrice.setText(((GoodsDetailModel.ResultDataBean.GoodsSpecificationDetailsBean) this.goodsSpecificationDetailsBeans.get(i)).getPrice() + "");
                this.goodsSpecNo.setText(((GoodsDetailModel.ResultDataBean.GoodsSpecificationDetailsBean) this.goodsSpecificationDetailsBeans.get(i)).getIdentifier());
                if (((GoodsDetailModel.ResultDataBean.GoodsSpecificationDetailsBean) this.goodsSpecificationDetailsBeans.get(i)).getGoodsDisplayPictures().size() > 0) {
                    paramString = ((GoodsDetailModel.ResultDataBean.GoodsSpecificationDetailsBean.GoodsDisplayPicturesBean) ((GoodsDetailModel.ResultDataBean.GoodsSpecificationDetailsBean) this.goodsSpecificationDetailsBeans.get(i)).getGoodsDisplayPictures().get(0)).getPicUrl();
                    Glide.with(paramContext).asBitmap().apply(new RequestOptions().placeholder(R.drawable.img_noimg_xs).error(R.drawable.img_lose_xs)).load("http://117.158.178.202:8001/JLMIS/" + paramString).into(this.goodsSpecImg);
                }
            } else {
                int j = Integer.parseInt(this.tvBuyNum.getText().toString().trim());
                if ((paramResultDataBean.getZeroStock() != 0) || (((GoodsDetailModel.ResultDataBean.GoodsSpecificationDetailsBean) this.goodsSpecificationDetailsBeans.get(i)).getGxcGoodsState() != 2)) {
                }
                if (j < ((GoodsDetailModel.ResultDataBean.GoodsSpecificationDetailsBean) this.goodsSpecificationDetailsBeans.get(i)).getGxcGoodsStock()) {
                } else {
                    this.tReduce.setTextColor(paramContext.getResources().getColor(R.color.moreText));
                    i += 1;
                    Glide.with(paramContext).asBitmap().apply(new RequestOptions().placeholder(R.drawable.img_noimg_xs).error(R.drawable.img_lose_xs)).load(R.drawable.img_noimg_xs).into(this.goodsSpecImg);
                    this.tvAdd.setTextColor(paramContext.getResources().getColor(R.color.trans_333333));
                    this.tvAdd.setTextColor(paramContext.getResources().getColor(R.color.trans_333333));
                }
                this.tvAdd.setTextColor(paramContext.getResources().getColor(R.color.moreText));
            }

        }
        this.goodsSpecificationRecyclerView.setLayoutManager(new GridLayoutManager(paramContext, 3));
        this.goodsMsgSpecificationAdapter = new GoodsMsgSpecificationAdapter(2131361883, this.goodsSpecificationDetailsBeans);
        this.goodsMsgSpecificationAdapter.setCheckedGoodsSpc(this.checkedGoodsSpec);
        this.goodsSpecificationRecyclerView.setAdapter(this.goodsMsgSpecificationAdapter);
        this.goodsMsgSpecificationAdapter.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(BaseQuickAdapter paramAnonymousBaseQuickAdapter, View paramAnonymousView, int paramAnonymousInt) {
                TextView tvDetail = (TextView) paramAnonymousView.findViewById(R.id.goods_spec_detail);
                tvDetail.setBackgroundResource(R.drawable.bg_text_green_border);
                tvDetail.setTextColor(paramContext.getResources().getColor(R.color.checkGreenColor));
                if (("".equals(GoodsDetailActivityChooseGoodsSpecPopu.this.checkedGoodsSpec)) || (!GoodsDetailActivityChooseGoodsSpecPopu.this.checkedGoodsSpec.equals(tvDetail.getText().toString().trim()))) {
                    GoodsDetailActivityChooseGoodsSpecPopu.this.checkedGoodsSpec = tvDetail.getText().toString().trim();
                    GoodsDetailActivityChooseGoodsSpecPopu.this.checkedGoodsSpecId = Integer.valueOf(((GoodsDetailModel.ResultDataBean.GoodsSpecificationDetailsBean) GoodsDetailActivityChooseGoodsSpecPopu.this.goodsSpecificationDetailsBeans.get(paramAnonymousInt)).getId());
                    GoodsDetailActivityChooseGoodsSpecPopu.this.goodsId = Integer.valueOf(((GoodsDetailModel.ResultDataBean.GoodsSpecificationDetailsBean) GoodsDetailActivityChooseGoodsSpecPopu.this.goodsSpecificationDetailsBeans.get(paramAnonymousInt)).getGoodsId());
                    GoodsDetailActivityChooseGoodsSpecPopu.this.goodsMsgSpecificationAdapter.setCheckedGoodsSpc(GoodsDetailActivityChooseGoodsSpecPopu.this.checkedGoodsSpec);
                    GoodsDetailActivityChooseGoodsSpecPopu.this.goodsMsgSpecificationAdapter.notifyDataSetChanged();
                    paramAnonymousInt = 0;
                    if (paramAnonymousInt < GoodsDetailActivityChooseGoodsSpecPopu.this.goodsSpecificationDetailsBeans.size()) {
                        if (GoodsDetailActivityChooseGoodsSpecPopu.this.checkedGoodsSpec.equals(((GoodsDetailModel.ResultDataBean.GoodsSpecificationDetailsBean) GoodsDetailActivityChooseGoodsSpecPopu.this.goodsSpecificationDetailsBeans.get(paramAnonymousInt)).getSpecifications())) {
                            GoodsDetailActivityChooseGoodsSpecPopu.this.goodsSpecPrice.setText(((GoodsDetailModel.ResultDataBean.GoodsSpecificationDetailsBean) GoodsDetailActivityChooseGoodsSpecPopu.this.goodsSpecificationDetailsBeans.get(paramAnonymousInt)).getPrice() + "");
                            GoodsDetailActivityChooseGoodsSpecPopu.this.goodsSpecNo.setText(((GoodsDetailModel.ResultDataBean.GoodsSpecificationDetailsBean) GoodsDetailActivityChooseGoodsSpecPopu.this.goodsSpecificationDetailsBeans.get(paramAnonymousInt)).getIdentifier());
                            if (((GoodsDetailModel.ResultDataBean.GoodsSpecificationDetailsBean) GoodsDetailActivityChooseGoodsSpecPopu.this.goodsSpecificationDetailsBeans.get(paramAnonymousInt)).getGoodsDisplayPictures().size() <= 0) {
                            }
                            String picUrl = ((GoodsDetailModel.ResultDataBean.GoodsSpecificationDetailsBean.GoodsDisplayPicturesBean) ((GoodsDetailModel.ResultDataBean.GoodsSpecificationDetailsBean) GoodsDetailActivityChooseGoodsSpecPopu.this.goodsSpecificationDetailsBeans.get(paramAnonymousInt)).getGoodsDisplayPictures().get(0)).getPicUrl();
                            Glide.with(paramContext).asBitmap().apply(new RequestOptions().placeholder(R.drawable.img_noimg_xs).error(R.drawable.img_lose_xs)).load("http://117.158.178.202:8001/JLMIS/" + picUrl).into(GoodsDetailActivityChooseGoodsSpecPopu.this.goodsSpecImg);
                        }
                        for (; ; ) {
                            paramAnonymousInt += 1;
                            Glide.with(paramContext).asBitmap().apply(new RequestOptions().placeholder(R.drawable.img_noimg_xs).error(R.drawable.img_lose_xs)).load(Integer.valueOf(R.drawable.img_noimg_xs)).into(GoodsDetailActivityChooseGoodsSpecPopu.this.goodsSpecImg);
                        }
                    }
                }
            }
        });
        this.tvAdd.setOnClickListener(new OnClickListener() {
            public void onClick(View paramAnonymousView) {
                if (!"".equals(GoodsDetailActivityChooseGoodsSpecPopu.this.tvBuyNum.getText().toString().trim())) {
                    int j = Integer.parseInt(GoodsDetailActivityChooseGoodsSpecPopu.this.tvBuyNum.getText().toString().trim());
                    if (j >= 500) {
                        Toast.makeText(paramContext, "已到库存上限!", Toast.LENGTH_SHORT).show();
                        GoodsDetailActivityChooseGoodsSpecPopu.this.tvAdd.setTextColor(paramContext.getResources().getColor(R.color.moreText));


                        GoodsDetailActivityChooseGoodsSpecPopu.this.tReduce.setTextColor(paramContext.getResources().getColor(R.color.trans_333333));
                        GoodsDetailActivityChooseGoodsSpecPopu.this.tvBuyNum.setText("500");
                        GoodsDetailActivityChooseGoodsSpecPopu.this.tvAdd.setTextColor(paramContext.getResources().getColor(R.color.moreText));
                    } else {

                        GoodsDetailActivityChooseGoodsSpecPopu.this.tvBuyNum.setText(j + 1 + "");
                        if (j + 1 == 500) {
                            GoodsDetailActivityChooseGoodsSpecPopu.this.tvAdd.setTextColor(paramContext.getResources().getColor(R.color.moreText));
                            GoodsDetailActivityChooseGoodsSpecPopu.this.tReduce.setTextColor(paramContext.getResources().getColor(R.color.trans_333333));
                            GoodsDetailActivityChooseGoodsSpecPopu.this.tvAdd.setTextColor(paramContext.getResources().getColor(R.color.trans_333333));

                            GoodsDetailActivityChooseGoodsSpecPopu.this.tvAdd.setTextColor(paramContext.getResources().getColor(R.color.moreText));
                            GoodsDetailActivityChooseGoodsSpecPopu.this.tReduce.setTextColor(paramContext.getResources().getColor(R.color.trans_333333));
                            GoodsDetailActivityChooseGoodsSpecPopu.this.tvAdd.setTextColor(paramContext.getResources().getColor(R.color.trans_333333));
                        }

                    }
                } else {
                    Toast.makeText(paramContext, "请输入购买数量", Toast.LENGTH_SHORT).show();
                }
            }
        });
        this.tvBuyNum.setInputType(3);
        this.tvBuyNum.setInputType(2);
        this.tvBuyNum.addTextChangedListener(new TextWatcher() {
            public void afterTextChanged(Editable paramAnonymousEditable) {
                if (!"".equals(GoodsDetailActivityChooseGoodsSpecPopu.this.tvBuyNum.getText().toString().trim())) {
                    if (Integer.parseInt(GoodsDetailActivityChooseGoodsSpecPopu.this.tvBuyNum.getText().toString().trim()) <= 0) {
                        GoodsDetailActivityChooseGoodsSpecPopu.this.tvBuyNum.setText("1");
                    }
                    if (Integer.parseInt(GoodsDetailActivityChooseGoodsSpecPopu.this.tvBuyNum.getText().toString().trim()) > 1) {
                        GoodsDetailActivityChooseGoodsSpecPopu.this.tReduce.setTextColor(paramContext.getResources().getColor(R.color.trans_333333));
                    }
                    int i = 0;
                    if (i < GoodsDetailActivityChooseGoodsSpecPopu.this.goodsSpecificationDetailsBeans.size()) {
                        if (((GoodsDetailModel.ResultDataBean.GoodsSpecificationDetailsBean) GoodsDetailActivityChooseGoodsSpecPopu.this.goodsSpecificationDetailsBeans.get(i)).getId() == GoodsDetailActivityChooseGoodsSpecPopu.this.checkedGoodsSpecId.intValue()) {
                            if ((paramResultDataBean.getZeroStock() != 0) || (((GoodsDetailModel.ResultDataBean.GoodsSpecificationDetailsBean) GoodsDetailActivityChooseGoodsSpecPopu.this.goodsSpecificationDetailsBeans.get(i)).getGxcGoodsState() != 2)) {
                            }
                            if (Integer.parseInt(GoodsDetailActivityChooseGoodsSpecPopu.this.tvBuyNum.getText().toString().trim()) <= ((GoodsDetailModel.ResultDataBean.GoodsSpecificationDetailsBean) GoodsDetailActivityChooseGoodsSpecPopu.this.goodsSpecificationDetailsBeans.get(i)).getGxcGoodsStock()) {
                            }
                            Toast.makeText(paramContext, "库存上限为" + ((GoodsDetailModel.ResultDataBean.GoodsSpecificationDetailsBean) GoodsDetailActivityChooseGoodsSpecPopu.this.goodsSpecificationDetailsBeans.get(i)).getGxcGoodsStock(), Toast.LENGTH_SHORT).show();
                            GoodsDetailActivityChooseGoodsSpecPopu.this.tvBuyNum.setText(((GoodsDetailModel.ResultDataBean.GoodsSpecificationDetailsBean) GoodsDetailActivityChooseGoodsSpecPopu.this.goodsSpecificationDetailsBeans.get(i)).getGxcGoodsStock() + "");
                            GoodsDetailActivityChooseGoodsSpecPopu.this.tvAdd.setTextColor(paramContext.getResources().getColor(R.color.moreText));
                        } else {
                            if (Integer.parseInt(GoodsDetailActivityChooseGoodsSpecPopu.this.tvBuyNum.getText().toString().trim()) > 500) {
                                GoodsDetailActivityChooseGoodsSpecPopu.this.tvBuyNum.setText("500");
                                GoodsDetailActivityChooseGoodsSpecPopu.this.tvAdd.setTextColor(paramContext.getResources().getColor(R.color.moreText));
                            } else {
                                GoodsDetailActivityChooseGoodsSpecPopu.this.tvAdd.setTextColor(paramContext.getResources().getColor(R.color.trans_333333));
                                if (Integer.parseInt(GoodsDetailActivityChooseGoodsSpecPopu.this.tvBuyNum.getText().toString().trim()) > 500) {
                                    GoodsDetailActivityChooseGoodsSpecPopu.this.tvBuyNum.setText("500");
                                    GoodsDetailActivityChooseGoodsSpecPopu.this.tvAdd.setTextColor(paramContext.getResources().getColor(R.color.moreText));
                                } else {
                                    GoodsDetailActivityChooseGoodsSpecPopu.this.tvAdd.setTextColor(paramContext.getResources().getColor(R.color.trans_333333));
                                }
                            }
                        }
                    }
                }
            }

            public void beforeTextChanged(CharSequence paramAnonymousCharSequence, int paramAnonymousInt1, int paramAnonymousInt2, int paramAnonymousInt3) {
            }

            public void onTextChanged(CharSequence paramAnonymousCharSequence, int paramAnonymousInt1, int paramAnonymousInt2, int paramAnonymousInt3) {
            }
        });
        this.tReduce.setOnClickListener(new OnClickListener() {
            public void onClick(View paramAnonymousView) {
                if (!"".equals(GoodsDetailActivityChooseGoodsSpecPopu.this.tvBuyNum.getText().toString().trim())) {
                    int j = Integer.parseInt(GoodsDetailActivityChooseGoodsSpecPopu.this.tvBuyNum.getText().toString().trim());
                    if (j <= 1) {
                        Toast.makeText(paramContext, "不能再减少了!", Toast.LENGTH_SHORT).show();
                        GoodsDetailActivityChooseGoodsSpecPopu.this.tReduce.setTextColor(paramContext.getResources().getColor(R.color.moreText));
                    } else if (j - 1 == 1) {
                        GoodsDetailActivityChooseGoodsSpecPopu.this.tvBuyNum.setText(j - 1 + "");
                        GoodsDetailActivityChooseGoodsSpecPopu.this.tReduce.setTextColor(paramContext.getResources().getColor(R.color.moreText));
                    }

                    int i = 0;
                    if (i < GoodsDetailActivityChooseGoodsSpecPopu.this.goodsSpecificationDetailsBeans.size()) {
                        if (((GoodsDetailModel.ResultDataBean.GoodsSpecificationDetailsBean) GoodsDetailActivityChooseGoodsSpecPopu.this.goodsSpecificationDetailsBeans.get(i)).getId() == GoodsDetailActivityChooseGoodsSpecPopu.this.checkedGoodsSpecId.intValue()) {
                            if ((paramResultDataBean.getZeroStock() != 0) || (((GoodsDetailModel.ResultDataBean.GoodsSpecificationDetailsBean) GoodsDetailActivityChooseGoodsSpecPopu.this.goodsSpecificationDetailsBeans.get(i)).getGxcGoodsState() != 2)) {
                            }
                            if (j - 1 >= ((GoodsDetailModel.ResultDataBean.GoodsSpecificationDetailsBean) GoodsDetailActivityChooseGoodsSpecPopu.this.goodsSpecificationDetailsBeans.get(i)).getGxcGoodsStock()) {
                            }
                            GoodsDetailActivityChooseGoodsSpecPopu.this.tvAdd.setTextColor(paramContext.getResources().getColor(R.color.trans_333333));
                        }
                    } else {
                        GoodsDetailActivityChooseGoodsSpecPopu.this.tvAdd.setTextColor(paramContext.getResources().getColor(R.color.moreText));
                        GoodsDetailActivityChooseGoodsSpecPopu.this.tvAdd.setTextColor(paramContext.getResources().getColor(R.color.trans_333333));
                    }
                } else {
                    Toast.makeText(paramContext, "请输入购买数量", Toast.LENGTH_SHORT).show();
                }
            }
        });
        this.okBtn.setOnClickListener(new OnClickListener() {
            public void onClick(View paramAnonymousView) {
                if (GoodsDetailActivityChooseGoodsSpecPopu.this.onClickOkBtnListener != null) {
                    GoodsDetailActivityChooseGoodsSpecPopu.this.onClickOkBtnListener.OnClickOkBtn(GoodsDetailActivityChooseGoodsSpecPopu.this.goodsId, GoodsDetailActivityChooseGoodsSpecPopu.this.checkedGoodsSpecId, Integer.valueOf(Integer.parseInt(GoodsDetailActivityChooseGoodsSpecPopu.this.tvBuyNum.getText().toString().trim())), GoodsDetailActivityChooseGoodsSpecPopu.this.isPresell);
                }
            }
        });
        setContentView(this.view);
        setWidth(-1);
        setHeight(-1);
        setFocusable(true);
        setAnimationStyle(R.style.AnimBottom);
        setBackgroundDrawable(null);
        this.textView.setOnClickListener(new OnClickListener() {
            public void onClick(View paramAnonymousView) {
                GoodsDetailActivityChooseGoodsSpecPopu.this.dismiss();
            }
        });
        this.closeBtn.setOnClickListener(new OnClickListener() {
            public void onClick(View paramAnonymousView) {
                GoodsDetailActivityChooseGoodsSpecPopu.this.dismiss();
            }
        });
    }

    public void setOnClickOkBtnListener(OnClickOkBtnListener paramOnClickOkBtnListener) {
        this.onClickOkBtnListener = paramOnClickOkBtnListener;
    }

    public static abstract interface OnClickOkBtnListener {
        public abstract void OnClickOkBtn(Integer paramInteger1, Integer paramInteger2, Integer paramInteger3, Integer paramInteger4);
    }
}


/* Location:              /Users/davidzhang/Documents/decompileApk/jlfood-dex2jar.jar!/com/jl/jlapp/popu/GoodsDetailActivityChooseGoodsSpecPopu.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */